package cn.ym.system.service.impl;


import cn.ym.basic.mapper.BaseMapper;
import cn.ym.basic.service.impl.BaseServiceImpl;
import cn.ym.system.domain.Systemdictionarytype;
import cn.ym.system.domain.Systemdictionarydetail;
import cn.ym.system.mapper.SystemdictionarydetailMapper;
import cn.ym.system.service.ISystemdictionarytypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SystemdictionarytypeServiceImpl extends BaseServiceImpl<Systemdictionarytype> implements ISystemdictionarytypeService {


    @Autowired
    private BaseMapper<Systemdictionarytype> baseMapper;

    @Autowired
    private SystemdictionarydetailMapper systemdictionarydetailMapper;


    @Override//删除级联
    public void delete(Long id) {

        List<Systemdictionarydetail> Systemdictionarydetails = systemdictionarydetailMapper.findAll();
        //循环
        for (Systemdictionarydetail systemdictionarydetail : Systemdictionarydetails) {
            if (systemdictionarydetail.getTypes_id()==id) {
                Long id1 = systemdictionarydetail.getId();
                systemdictionarydetailMapper.delete(id1);
            }
        }
        super.delete(id);
    }


    //抽屉明细
    @Override
    public List<Systemdictionarydetail> loadquery(Long id) {
        //创建了一个集合来装字典明细
        ArrayList<Systemdictionarydetail> objects = new ArrayList<>();
        //执行字典明细的查询全部方法
        List<Systemdictionarydetail> list = systemdictionarydetailMapper.findAll();
        //遍历
        for (Systemdictionarydetail systemdictionarydetail : list) {
                //获取字典明细的type-id
            Long types_id = systemdictionarydetail.getTypes_id();
            //对比前端传过来的id和tpye_id相等
            if (types_id==id){

                objects.add(systemdictionarydetail);
            }
        }
        return objects;
    }


}
